import { ref, computed ,reactive} from 'vue'
import { defineStore } from 'pinia'


// pinia 定义公共状态和方法
// 组合式
// 1. defineStore('counter', callback)  组合式写法要求第二参数传入回调函数(setup函数)  => 回调函数的返回值,就是store实例中存储的数据
// 2. 定义数据的方法同Vue3  ref shallowRef reactive shallowReactive computed 

export const useCounterStore = defineStore('counter', () => { 
  const count = ref(0)
  const zhang = reactive({
    name:"张三",
    age:18
  })
  const doubleCount = computed(() => count.value * 2)
  function increment() {
    count.value++
  }
  return { count, doubleCount, increment,zhang}
})
